package cn.edu.ntu.yyl.fitter;

import cn.edu.ntu.yyl.pojo.user.UserInfo;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UserFitter implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        UserInfo userinfo = (UserInfo) request.getSession().getAttribute("userInfo");
        //用户未登录
        if(request.getSession().getAttribute("userInfo") == null){
            //重定向到登录页面
            response.sendRedirect("/login");
            return false ;
            //用户已登录
        } else return true;
    }
}
